{{--继承模板--}}
@extends('admin.layouts.common')
@section('content')
    <br>
    <div class="layui-anim layui-anim-up">
        <form class="layui-form">
            <input type="hidden" value="{{$id}}" name="id">
            <div class="layui-container">
                <div class="layui-row">
                    <div class="layui-form-item">
                        <label class="layui-form-label">密码</label>
                        <div class="layui-input-inline">
                            <input type="password" name="password" autocomplete="off" placeholder="请输入密码" class="layui-input" lay-verify="required">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label">确认密码</label>
                        <div class="layui-input-inline">
                            <input type="password" name="repassword" placeholder="请确认密码" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button type="submit" class="layui-btn layui-btn-black" lay-submit="" lay-filter="editpass">修改</button>
                            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <script src="{{asset('layuiadmin/layui/layui.js')}}"></script>
    <script>
        layui.use(['form','layer'], function(){
            var form = layui.form
                ,layer = layui.layer
                ,$ = layui.jquery;
            //监听提交
            var _token =  $('meta[name="csrf-token"]').attr('content');
            form.on('submit(editpass)', function(data){
                var infos = data.field;
                if(!(/^[a-zA-Z0-9_-]{6,20}$/).test(infos.password)){
                    layer.msg("密码请使用6-20位英文，数字及下划线组合");
                    return false;
                }

                if(infos.repassword != infos.password){
                    layer.msg("两次密码输入不一致");
                    return false;
                }
                data.field._token = _token;
                $.post("{{url('admin/auth/editpass')}}",data.field,function(res){
                    if(res.code == 1){
                        layer.msg(res.msg,function () {
                            window.location.reload();
                        });
                    }else{
                        layer.msg(res.msg);
                    }
                },'json')
                return false;
            });
        });
    </script>
@endsection